//
//  LCWithdrawalViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/4/8.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCWithdrawalViewController.h"
#import "LCUserModel.h"
#import "LCMineService.h"

#import "LCBDWeChatViewController.h"
#import "LCBDAliPayViewController.h"

@interface LCWithdrawalViewController ()

@property (weak, nonatomic) IBOutlet UILabel *amountLb;

@property (weak, nonatomic) IBOutlet UITextField *cashAmountTfl;

@end

@implementation LCWithdrawalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
}

-(void)configUI {
    LCUserModel * userModel = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
    self.amountLb.text = kFORMAT(@"%@",userModel.assets.UserAmount.value);
}

- (IBAction)backAction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)withdrawalBtnAction:(UIButton *)sender {
    LCUserModel * userModel = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
    if ([self.cashAmountTfl.text isEqualToString:@""]) {
        [self showErrorText:@"请输入提现金额"];
        return;
    }
    
    if ([self.cashAmountTfl.text floatValue] > [userModel.assets.UserAmount.value floatValue]) {
        [self showErrorText:@"账户余额不足"];
        return;
    }
    
    if ([userModel.alipay.bankid integerValue] == 0) {
        [self showAlertWithTitle:@"" andMesage:@"请先绑定支付宝" andCancel:^(id cancel) {
        } Determine:^(id determine) {
            LCBDAliPayViewController * pushVC = [LCBDAliPayViewController xx_instantiateFromStoryboardNamed:@"MineBind"];
            pushVC.alipay = userModel.alipay;
            [self.navigationController pushViewController:pushVC animated:YES];
        }];
        return;
    }
    
    [LCMineService withdrawalWithModel:@"支付宝" CashAmount:self.cashAmountTfl.text Block:^(BOOL isSuccess) {
        if (isSuccess) {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }];
}

@end
